package com.ebt.m.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.view.View;

import com.ebt.m.activity.WebBaseActivity;
import com.ebt.m.commons.utils.Logger;
import com.ebt.m.customer.constant.CustomerConstant;
import com.ebt.m.customer.ui.PolicyDetailWebActivity;
import com.tendcloud.tenddata.TCAgent;

/**
 * Created by andy on 16-5-18.
 */
public class ClickSpanForNet extends ClickableSpan {
    private int activeType;
    private String id;
    private Context context;
    private Object extra;

    public ClickSpanForNet(Context context, int activeType, String id, Object extra) {
        this.activeType = activeType;
        this.id = id;
        this.context = context;
        this.extra = extra;
    }

    @Override
    public void onClick(View widget) {
        try {
            switch (activeType) {
                case CustomerConstant.InteractionType.CUSTOMER_CREATE:
                    //没有点击事件
                    break;
                case CustomerConstant.InteractionType.INSURANCE_CREATE:
                    gotoInsurance();
                    break;
                case CustomerConstant.InteractionType.INSURANCE_EDIT:
                    gotoInsurance();
                    break;
                case CustomerConstant.InteractionType.PROPOSAL_SEND:
//                    gotoProposal();
                    break;
                case CustomerConstant.InteractionType.PROPOSAL_READ:
//                    gotoProposal();
                    break;
                case CustomerConstant.InteractionType.NOTE_CREATE:

                    break;
                case CustomerConstant.InteractionType.NOTE_EDIT:

                    break;
                case CustomerConstant.InteractionType.PHONE_CALL:

                    break;
            }
            TCAgent.onEvent(context, "timeline_object_click", Integer.toString(activeType));
        } catch (Exception e) {
            Logger.e("clickspan", e);
        }
    }

    private void gotoInsurance() {
        if (!TextUtils.isEmpty(id)) {
            Bundle bundle = new Bundle();
            bundle.putString(WebBaseActivity.WEB_TYPE_TITLE, "保单详情");
            bundle.putInt(WebBaseActivity.WEB_TYPE_FRAGMENT, WebBaseActivity.FRAGMENT_4OLD_BASE);
            bundle.putBoolean(WebBaseActivity.WEB_TYPE_HIDE_TOOLBAR, false);
            bundle.putInt(WebBaseActivity.WEB_TYPE_FRAGMENT, 5);
            bundle.putString(WebBaseActivity.WEB_TYPE_LINK, CustomerConstant.Url.INSURANCE_BASE_URL + id);
            Intent intent = new Intent(context, PolicyDetailWebActivity.class);
            intent.putExtras(bundle);
            context.startActivity(intent);
        }
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }
}
